package com.wangp.springbootsource.controller;

import com.wangp.springbootsource.service.DemoService;
import com.wangp.springbootsource.valid.ValidDTO;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <pre>
 * classname DemoController
 * description
 * </pre>
 *
 * @author wangp
 * @date 2020/8/30 23:02
 **/
@RestController
public class DemoController {

    @Autowired
    private DemoService demoService;

    @GetMapping("/first")
    public String first() {
        return demoService.getApplicationContext().getEnvironment().getProperty("key1");
    }

    @GetMapping("/second")
    public String second() {
        return demoService.getApplicationContext().getEnvironment().getProperty("key2");
    }

    @GetMapping("/third")
    public String third() {
        return demoService.getApplicationContext().getEnvironment().getProperty("key3");
    }

    @PostMapping("/valid")
    public String valid(@Valid @RequestBody ValidDTO validDTO) {
        return validDTO.toString();
    }
}
